package com.itheima.sky.dao;

import com.itheima.sky.pojo.ShoppingCart;
import org.apache.ibatis.annotations.*;

import java.util.List;

/**
 * @Description ShoppingCartMapper
 * @Author jiangning
 * @Date 2024-06-29
 */
@Mapper
public interface ShoppingCartMapper {
    @Select("select * from shopping_cart where user_id = #{userId};")
    List<ShoppingCart> getCartListByUserId(Long userId);

    //c
    @Select("select * from shopping_cart sc where sc.user_id=#{userId} ")
    List<ShoppingCart> selectCartList(Long userId);

    // 查询购物车2
    //查询购物车是否存在该数据
    ShoppingCart findExist(ShoppingCart shoppingCart);

    // 添加购物车
    //添加购物车项
    @Insert("insert into shopping_cart values(null,#{name},#{image},#{userId},#{dishId},#{setmealId},#{dishFlavor},#{number},#{amount},#{createTime})")
    void insertCartList(ShoppingCart shoppingCart);
    //更新购物车
    @Update("update shopping_cart set number=#{number} where id=#{id}")
    void updateCartList(ShoppingCart shoppingCart);

    //删除购物车
    @Delete("delete from shopping_cart where user_id=#{userId}")
    void cleanCartList(Long userId);

    //根据菜id删除购物车对应商品数量number减一
    void deleteCart(Long dishId);

    //根据菜id查询购物车数量
    @Select("SELECT number FROM shopping_cart WHERE setmeal_id = #{setmeal_id}")
    Integer getNumber(Long setmeal_id);



    @Delete("delete from shopping_cart where user_id=#{userId}")
    void cleanUpCart(Long userId);

    @Update("update shopping_cart set number=number-1 where setmeal_id=#{setmealId} and user_id=#{userId}")
    void declineCart(Long setmealId, Long userId);

    @Select("select number from shopping_cart where setmeal_id = #{setmealId} and user_id=#{userId}")
    Integer getNumberBySetmealId(Long setmealId, Long userId);

    @Delete("delete from shopping_cart where setmeal_id = #{setmealId}  and user_id=#{userId}")
    void deleteCartOne(Long setmealId, Long userId);
}
